package consumer.demo.listeners;


import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class MqListener {

    @RabbitListener(queues = "simple.queue")
    public void listenSimpleQueue(String msg) {
        System.out.println("消费者收到了simple.queue的消息:【" + msg + "】");
    }

    @RabbitListener(queues = "work.queue")
    public void listenWorkQueue1(String msg) throws InterruptedException {
        System.out.println("消费者1收到了work.queue的消息:【" + msg + "】");
        Thread.sleep(20);

    }

    @RabbitListener(queues = "work.queue")
    public void listenWorkQueue2(String msg) throws InterruptedException {
        System.err.println("消费者2收到了work.queue的消息:【" + msg + "】");
        Thread.sleep(200);
    }

    @RabbitListener(queues = "fanout.queue1")
    public void listenFanout1(String msg) {
        System.out.println("消费者1收到了fanout.queue1的消息:【" + msg + "】");

    }

    @RabbitListener(queues = "fanout.queue2")
    public void listenFanout2(String msg) {
        System.out.println("消费者2收到了fanout.queue2的消息:【" + msg + "】");
    }

    @RabbitListener(queues = "direct.queue1")
    public void listenDirect1(String msg) {
        System.out.println("消费者1收到了direct.queue1的消息:【" + msg + "】");

    }

    @RabbitListener(queues = "direct.queue2")
    public void listenDirect2(String msg) {
        System.out.println("消费者2收到了direct.queue2的消息:【" + msg + "】");
    }

    @RabbitListener(queues = "topic.queue1")
    public void listenTopic1(String msg) {
        System.out.println("消费者1收到了topic.queue1的消息:【" + msg + "】");

    }

    @RabbitListener(queues = "topic.queue2")
    public void listenTopic2(String msg) {
        System.out.println("消费者2收到了topic.queue2的消息:【" + msg + "】");
    }
}
